package com.report.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.report.constants.TagConstants;
import com.report.dto.request.WebMemberReq;

import com.report.dto.response.MemberRes;
import com.report.dto.response.OrderRes;
import com.report.service.IMemberService;
import com.report.service.IOrderService;
import com.report.wx.WechatService;
import com.zmh.framework.redis.RedisCache;
import com.zmh.framework.sys.dto.request.common.PageResponseDTO;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author summer
 * @date 2024-06-29 21:42
 **/
@RestController
@RequestMapping(value = "/webMember")
@AllArgsConstructor
public class WebMemberController {

    private final IMemberService memberService;

    /**
     * 修改用户昵称
     * @param webMemberReq
     * @return
     */
    @PostMapping(value = "/editNickName")
    public Result<String> editNickName(@RequestBody WebMemberReq webMemberReq){
        Object loginId = StpUtil.getLoginId();
        memberService.editNickName(webMemberReq.getNickName(),Convert.convert(Integer.class, loginId));
        return Result.successResult();
    }

    /**
     * 获取用户信息
     * @return
     */
    @GetMapping(value = "/getUserInfo")
    public Result<MemberRes> getUserInfo(){
        MemberRes memberRes=memberService.getUserInfo();
        return Result.successResult(memberRes);
    }


    /**
     * 获取会员信息
     * @return
     */
    @GetMapping(value = "/getMemberInfo")
    public Result<MemberRes> getMemberInfo(){
        Object loginId = StpUtil.getLoginId();
        MemberRes member = memberService.findById(Convert.convert(Integer.class, loginId));
        return Result.successResult(member);
    }

    /**
     * 退出系统
     * @return
     */
    @GetMapping(value = "/logout")
    public Result<String> logout(){
        StpUtil.logout();
        return Result.successResult();
    }


    /**
     * 更新手机号码
     * @param webMemberRes
     * @return
     */
    @PostMapping(value = "/changePhone")
    public Result<String> changePhone(@RequestBody WebMemberReq webMemberRes){
        memberService.changePhone(webMemberRes);
        return Result.successResult();
    }

    private final IOrderService orderService;

    @PostMapping(value = "/memberOrderList")
    public Result<Page<OrderRes>> memberOrderList(@RequestBody PageResponseDTO pageResponseDTO){
        Page<OrderRes> orderRes= orderService.memberOrderList(pageResponseDTO);
        return Result.successResult(orderRes);
    }

}
